home *** CD-ROM | disk | FTP | other *** search
- /*
- Sysvars - example window program to display selected system variables in a window.
- Icon-bar menu allows pattern for variable names to be selected.
- Single-click launches variable window if none present.
- *
- Chris Dollin, January 1990
- Code may be freely mangled. No rights reserved. No warranty.
- */
-
- #include "wimp.h"
- #include "wimpt.h"
- #include "win.h"
- #include "event.h"
- #include "baricon.h"
- #include "res.h"
- #include "resspr.h"
- #include "menu.h"
- #include "template.h"
- #include "dbox.h"
- #include "werr.h"
- #include "txt.h"
- #include "flex.h"
- #include "heap.h"
- #include "visdelay.h"
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
-
- /*
- Sundry constants
- */
-
- #define Example_menu_info 1 /* Positions of menu items within bar-icon menu */
- #define Example_menu_filter 2 /* (info should be first; quit should be last) */
- #define Example_menu_quit 3
-
- #define Filter_Variable 0 /* Writeable icon inside selection box */
-
- #define Example_info_field 4 /* Position of version field in info box */
-
- /*
- Top-level data
- */
-
- static char *example_Version_String = "1.00 (30th November 1989)";
-
- static menu example_menu = (menu) 0;
-
- static txt a_text = (txt) NULL;
-
- static char Filter_Variable_String[100];
-
- /*
- Reading selected system variables and inserting their names & values into
- a txt buffer.
- */
-
- #define OS_READ_VAR_VAL 0x23
-
- static void sysvars_to_text( txt t, char *var_filter )
- {
- char buffer[255];
- os_error *err;
- os_regset regs;
- regs.r[0] = (int) var_filter;
- regs.r[1] = (int) buffer;
- regs.r[3] = (int) 0;
- txt_setdot( t, 0 );
- txt_delete( t, txt_size( t ) );
- visdelay_begin();
- do
- {
- regs.r[2] = sizeof( buffer );
- regs.r[4] = 3;
- err = os_swix( os_X | OS_READ_VAR_VAL, ®s );
- if (err == NULL && regs.r[2] > 0)
- {
- buffer[regs.r[2]] = '\0';
- txt_insertstring( t, buffer );
- txt_insertstring( t, " = " );
- txt_insertstring( t, (char *) regs.r[3] );
- txt_insertstring( t, "\n" );
- txt_setdot( t, txt_size( t ) );
- }
- }
- while (err == NULL);
- txt_setdot( t, 0 );
- visdelay_end();
- }
-
- /*
- Event handler called on a left click on the icon.
- */
-
- static void example_iconclick( wimp_i icon )
- {
- if (a_text == NULL) txt_show( a_text = txt_new( "<unset>" ) );
- txt_settitle( a_text, Filter_Variable_String );
- sysvars_to_text( a_text, Filter_Variable_String );
- }
-
- /*
- Display the program info box - called from the menu processor.
- */
-
- static void example_info_about_program(void)
- {
- dbox d = dbox_new( "ProgInfo" ); /* Dialogue box handle */
- if (d != NULL)
- {
- dbox_setfield( d, Example_info_field, example_Version_String );
- dbox_show( d );
- dbox_fillin( d );
- dbox_dispose( &d );
- }
- }
-
- /*
- Display dialogue box for filter setting
- */
-
-
- static void example_set_filters(void)
- {
- dbox d = dbox_new( "Variables" );
- if (d)
- {
- dbox_setfield( d, Filter_Variable, Filter_Variable_String );
- dbox_show( d );
- dbox_fillin( d );
- dbox_getfield( d, Filter_Variable, Filter_Variable_String, 100 );
- dbox_dispose( &d );
- }
- }
-
- /*
- Event handler for the menu.
- */
-
- static void example_menuproc(void *handle, char *hit)
- {
- handle = handle; /* We don't need the handle: this stops compiler warning */
-
- switch (hit[0])
- {
- case Example_menu_info:
- example_info_about_program();
- break;
-
- case Example_menu_filter:
- example_set_filters();
- if (a_text) example_iconclick( (wimp_i) 0 );
- break;
-
- case Example_menu_quit:
- exit(0);
- break;
- }
- }
-
- /*
- Initialise the program, returning TRUE if it was all OK.
- */
-
- static BOOL example_initialise(void)
- {
- flex_init(); /* Flex store management */
- heap_init( TRUE ); /* Heap store ditto */
- wimpt_init("Sysvars browser"); /* Main wimp initialisation */
- res_init("Sysvars"); /* Resources */
- resspr_init(); /* Application sprites */
- template_init(); /* Templates */
- dbox_init(); /* Dialogue boxes */
- visdelay_init(); /* For the hourglass */
-
- strcpy( Filter_Variable_String, "*" );
-
- if ((example_menu = menu_new("Example", ">Info,>Filter,Quit")) == NULL)
- return FALSE;
-
- baricon( "!Sysvars", 1 /* Wimp sprite area */, example_iconclick );
- if (!event_attachmenu( win_ICONBAR, example_menu, example_menuproc, 0 ))
- return FALSE;
-
- return TRUE;
- }
-
- /*
- At last, here's -main-.
- */
-
- int main( int argc, char *argv[] )
- {
- if (example_initialise())
- while (TRUE) event_process();
- return 0;
- }
-